import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:my_meeting/routes/router.dart';

import '../../../generated/assets.dart';
import '../../../generated/l10n.dart';
import '../../../global.dart';
import '../../../utils/utils.dart';
import '../../../widget/dialog/dialog_common_style.dart';
import 'metting_detail_logic.dart';

class Metting_detailPage extends GetView<Metting_detailLogic> {
  const Metting_detailPage({Key? key}) : super(key: key);

  Widget colorSpace() {
    return Container(
      color: const Color(0xFFF8FAFB),
      height: 6.h,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        centerTitle: true,
        title: Text(
          S.current.meeting,
          style: TextStyle(fontSize: 16.sp, fontWeight: FontWeight.w600),
        ),
        actions: [
          InkWell(
            onTap: () {
              Get.toNamed(AppRoutes.meetingEdit,arguments: controller.meetingData)?.then((value){
                if(value != null){
                  controller.meetingData.refresh();
                }
              });
            },
            child: SvgPicture.asset(
              Assets.svgEdit,
              width: 20,
              height: 20,
            ).paddingOnly(right: 12.w),
          ),
          InkWell(
            onTap: () {
              Get.dialog(CommonDialog(
                title: S.current.meetingDelTitle,
                content: S.current.meetingDelContent,
                posiTap: () {
                  global.deleteMeeting(controller.meetingData.value.id!).then((val){
                    Get.back(result: true);
                  });
                },
              ));
            },
            child: SvgPicture.asset(
              Assets.svgDelete,
              width: 20,
              height: 20,
            ).paddingOnly(right: 15.w),
          ),
        ],
      ),
      body: Container(
        color: Colors.white,
        padding: EdgeInsets.only(bottom: 15.h),
        child: Obx(() {
          String state = Utils.meetingState(controller.meetingData.value);
          return ListView(
            children: [
              Column(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        controller.meetingData.value.meetingName ?? '',
                        style: TextStyle(
                            fontSize: 16.sp, fontWeight: FontWeight.w600),
                      ),
                      Text(
                        state,
                        style: TextStyle(
                            color: Utils.stateColor(state),
                            fontSize: 12.sp,
                            fontWeight: FontWeight.w500),
                      )
                    ],
                  ).marginOnly(top: 30.h),
                  //会议内容
                  Container(
                    decoration: BoxDecoration(
                        color: const Color(0xFFE7EFFD),
                        borderRadius: BorderRadius.circular(8.r)),
                    margin: EdgeInsets.only(top: 20.h),
                    padding:
                        EdgeInsets.symmetric(horizontal: 10.w, vertical: 10.h),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Row(
                          children: [
                            Container(
                              width: 4.w,
                              height: 10.h,
                              decoration: BoxDecoration(
                                  color: const Color(0xFF1877FF),
                                  borderRadius: BorderRadius.circular(26.r)),
                            ),
                            Text(
                              S.current.meetingContent,
                              style: TextStyle(
                                  color: const Color(0xFF333333),
                                  fontSize: 13.sp,
                                  fontWeight: FontWeight.w500),
                            ).marginOnly(left: 5.w),
                          ],
                        ),
                        Text(
                          controller.meetingData.value.meetingContent ?? '',
                          style: TextStyle(
                              color: const Color(0xFF333333),
                              fontSize: 12.sp,
                              fontWeight: FontWeight.w400,
                              height: 1.67),
                        ).paddingOnly(top: 10.h, left: 9.w)
                      ],
                    ),
                  ),
                  Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text(
                            Utils.getMeetingTime(
                                controller.meetingData.value.meetingBeginTime),
                            style: TextStyle(
                                color: const Color(0xff333333),
                                fontSize: 16.sp,
                                fontWeight: FontWeight.w700),
                          ),
                          Text(
                            Utils.getMeetingDate(
                                controller.meetingData.value.meetingBeginTime),
                            style: TextStyle(
                                color: const Color.fromRGBO(51, 51, 51, 0.6),
                                fontSize: 12.sp,
                                fontWeight: FontWeight.w500),
                          )
                        ],
                      ),
                      Expanded(
                        child: Row(
                          children: [
                            Expanded(
                              child: Divider(
                                color: const Color.fromRGBO(0, 0, 0, 0.06),
                                endIndent: 5.w,
                                indent: 10.w,
                              ),
                            ),
                            Container(
                              padding: EdgeInsets.symmetric(horizontal: 10.w),
                              alignment: Alignment.center,
                              height: 18.h,
                              decoration: BoxDecoration(
                                  color: const Color.fromRGBO(51, 51, 51, 0.1),
                                  borderRadius: BorderRadius.circular(4.r)),
                              child: Text(
                                '${Utils.timeDifference(controller.meetingData.value.meetingBeginTime!, controller.meetingData.value.meetingEndTime!)}小时',
                                style: TextStyle(
                                    color: const Color(0xff333333),
                                    fontSize: 10.sp,
                                    fontWeight: FontWeight.w500),
                              ),
                            ),
                            Expanded(
                              child: Divider(
                                color: const Color.fromRGBO(0, 0, 0, 0.06),
                                endIndent: 10.w,
                                indent: 5.w,
                              ),
                            ),
                          ],
                        ),
                      ),
                      Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text(
                            Utils.getMeetingTime(
                                controller.meetingData.value.meetingEndTime),
                            style: TextStyle(
                                color: const Color(0xff333333),
                                fontSize: 16.sp,
                                fontWeight: FontWeight.w700),
                          ),
                          Text(
                            Utils.getMeetingDate(
                                controller.meetingData.value.meetingEndTime),
                            style: TextStyle(
                                color: const Color.fromRGBO(51, 51, 51, 0.6),
                                fontSize: 12.sp,
                                fontWeight: FontWeight.w500),
                          )
                        ],
                      ),
                    ],
                  ).marginOnly(
                      top: 20.h, left: 30.w, right: 30.w, bottom: 20.h),
                ],
              ).paddingSymmetric(horizontal: 15.w),
              colorSpace(),
              Column(
                children: [
                  Row(
                    children: [
                      Text(
                        S.current.meetingRoom,
                        style: TextStyle(
                            color: const Color(0xFF333333),
                            fontSize: 14.sp,
                            fontWeight: FontWeight.w500),
                      ),
                      Expanded(
                        child: Text(
                          controller.meetingData.value.meetingAddress ?? '',
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                              color: const Color(0xFF666666),
                              fontSize: 14.sp,
                              fontWeight: FontWeight.w400),
                        ).paddingOnly(left: 30.w),
                      )
                    ],
                  ),
                  Row(
                    children: [
                      Text(
                        S.current.meetingPerson,
                        style: TextStyle(
                            color: const Color(0xFF333333),
                            fontSize: 14.sp,
                            fontWeight: FontWeight.w500),
                      ),
                      Expanded(
                        child: Text(
                          controller.meetingData.value.participants ?? '',
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                              color: const Color(0xFF666666),
                              fontSize: 14.sp,
                              fontWeight: FontWeight.w400),
                        ).paddingOnly(left: 30.w),
                      )
                    ],
                  ).marginOnly(top: 20.h)
                ],
              ).paddingSymmetric(vertical: 20.h, horizontal: 15.w),
              colorSpace(),
              GestureDetector(
                onTap: () {
                  Get.toNamed(AppRoutes.mettingRecord)?.then((value){
                    if(value != null){
                      controller.meetingData.value.meetingMinutes = value;
                      controller.meetingData.refresh();
                      global.updateMeeting(controller.meetingData.value);
                    }
                  });
                },
                child: Container(
                  color: Colors.white,
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            S.current.meetingMinutes,
                            style: TextStyle(
                                color: const Color(0xFF333333),
                                fontSize: 14.sp,
                                fontWeight: FontWeight.w500),
                          ),
                          SvgPicture.asset(
                            Assets.svgArrowRight,
                            width: 14,
                            height: 14,
                            color: const Color(0xFF333333),
                          ),
                        ],
                      ),
                      Obx(() {
                        return !Utils.stringIsEmpty(controller.meetingData.value.meetingMinutes) ?
                           Container(
                          width: double.infinity,
                          decoration: BoxDecoration(
                              color: const Color(0xFFF4F4F4),
                              borderRadius: BorderRadius.circular(8.r)),
                          margin: EdgeInsets.only(top: 10.h),
                          padding: EdgeInsets.symmetric(
                              horizontal: 10.w, vertical: 10.h),
                          child: Text(
                            controller.meetingData.value.meetingMinutes ?? '',
                            style: TextStyle(
                                color: const Color(0xFF666666),
                                fontSize: 12.sp,
                                fontWeight: FontWeight.w400,
                                height: 1.67),
                          ),
                        ) : Container();
                      })
                    ],
                  )
                      .marginSymmetric(horizontal: 15.w)
                      .paddingSymmetric(vertical: 20.h),
                ),
              ),
              colorSpace(),
              GestureDetector(
                onTap: () {
                  // Get.dialog(MeetDeviceTime(
                  //   callback: (index) {
                  //     debugPrint(index.toString());
                  //   },
                  // ), barrierDismissible: true);
                },
                child: Container(
                  color: Colors.white,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        S.current.meetingDeviceOpen,
                        style: TextStyle(
                            color: const Color(0xFF333333),
                            fontSize: 14.sp,
                            fontWeight: FontWeight.w500),
                      ),
                      Row(
                        children: [
                          Text(
                            controller.meetingData.value.deviceOpen ?? '',
                            style: TextStyle(
                                color: const Color(0xFF666666),
                                fontSize: 14.sp,
                                fontWeight: FontWeight.w400),
                          ),
                          // SvgPicture.asset(
                          //   Assets.svgArrowRight,
                          //   width: 14,
                          //   height: 14,
                          //   color: const Color(0xFF333333),
                          // )
                        ],
                      ),
                    ],
                  )
                      .marginSymmetric(horizontal: 15.w)
                      .paddingOnly(top: 20.h, bottom: 20.h),
                ),
              )
            ],
          );
        }),
      ),
    );
  }
}
